<template>
    <a-button type="primary" @click="handleClick" style="margin-left: 10px;">
        连读
    </a-button>
</template>

<script setup>
import { message } from "ant-design-vue";
import { ref , watch} from "vue";

import ContinuousFn from "./continuous-fn.js";

const fn = ref();
const onOpen = (editor) => {
    if (!fn.value && editor) {
        // console.log("onOpen");
        fn.value = new ContinuousFn(editor);
    }
};

function handleClick(editor) {
    if (fn.value.isDisabled()) {
        return;
    }
    fn.value?.exec();
}

const props = defineProps({
    editor: {
        type: Object,
        default: null,
    },
});

watch(
    () => props.editor,
    (val) => {
        // console.log("props.editor", props.editor)
        onOpen(props.editor);
    },
    { immediate: true, deep: true }
);

// 调用这个函数将子组件的一些数据和方法暴露出去
defineExpose({
    onOpen,
});
</script>

<style lang="scss" scoped></style>
